package com.tanhua.app.controller;

import com.tanhua.app.service.CommentService;
import com.tanhua.app.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private CommentService commentService;

    @PostMapping(value = "/messages/contacts", name = "添加联系人")
    public ResponseEntity addContacts(@RequestBody Map<String, String> param) {

        Long friendId = Long.valueOf(param.get("userId"));
        return messageService.addContacts(friendId);
    }

    @GetMapping(value = "/messages/contacts", name = "查看联系人")
    public ResponseEntity findContactsByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return messageService.findContactsByPage(pageNum, pageSize);
    }

    @GetMapping(value = "/messages/likes", name = "被点赞用户列表")
    public ResponseEntity messagesLikes(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 1;
        return commentService.findUserCommentVoByPage(pageNum, pageSize, commentType);
    }

    @GetMapping(value = "/messages/comments", name = "被评论户用户列表")
    public ResponseEntity messagesComments(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 2;
        return commentService.findUserCommentVoByPage(pageNum, pageSize, commentType);
    }

    @GetMapping(value = "/messages/loves", name = "被点喜欢用户列表")
    public ResponseEntity messagesLoves(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 3;
        return commentService.findUserCommentVoByPage(pageNum, pageSize, commentType);
    }

    @GetMapping(value = "/messages/announcements", name = "公告列表")
    public ResponseEntity findAnnouncementsByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return messageService.findAnnouncementsByPage(pageNum, pageSize);
    }
}
